﻿ 
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using VueOnDotnetcore.Controllers.Contexts;
using VueOnDotnetcore.Models;

namespace VueOnDotnetcore.Controllers
{
    public class HeroController : Controller
    {
        static HeroContext _context = new HeroContext();


        // GET: Hero
        public ActionResult Index()
        {
            return View();
        }
 
        [HttpGet]
        public JsonResult Get()
        {
            return Json(_context.Get() );
        }

        [HttpPost]
        public JsonResult Add(Hero hero)
        {
            _context.Add(hero);
            return Json(_context.Get());
        }

        [HttpPost]
        public JsonResult Update(int idx, Hero hero)
        { 
            _context.Update(idx,hero);
            return Json(_context.Get());
        }

        [HttpPost]
        public JsonResult Delete(  string name)
        { 
            _context.Delete(name);
            Debug.WriteLine($"Delete({name})");
            return Json(_context.Get());
        }
    }
}
